<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>DataType.Date Tests</title>
<script type="text/javascript" src="../../../build/yui/yui.js"></script>
</head>

<body class="yui3-skin-sam">
<h1>DataType.Date Tests</h1>
<p><input type="button" value="Run Tests" id="btnRun" disabled=true></p>

<script type="text/javascript">

(function() {
    var dateUS, dateFR, dateKR;

    YUI({
        lang: "en-US"
    }).use("datatype-date", function(Y) {
        dateUS = Y.DataType.Date;
    });

    YUI({
        filter:"raw",
        lang: "fr-FR"
    }).use("datatype-date", function(Y) {
        dateFR = Y.DataType.Date;
    });
    
    YUI({
        filter:"debug",
        lang: "ko-KR"
    }).use("datatype-date", function(Y) {
        dateKR = Y.DataType.Date;
    });

    YUI({
        //filter: "debug",
        logInclude:{"TestRunner":true},
        useConsole: true
    }).use("console", "test", "dump", "datatype-date", "node", function(Y) {
        
        // Set up the page
        var LANG = Y.Lang,
            ASSERT = Y.Assert,
            ARRAYASSERT = Y.ArrayAssert,
            btnRun = Y.one("#btnRun"),
            myConsole = new Y.Console().render();
            
        btnRun.set("disabled", false);
        Y.on("click", function(){
            Y.Test.Runner.run();
        }, btnRun);


        var testParse = new Y.Test.Case({
            name: "Date Parse Tests",
        
            testUndefined: function() {
                var date = Y.DataType.Date.parse();
                ASSERT.isNull(date, "Expected null.");
            },

            testNull: function() {
                var date = Y.DataType.Date.parse(null);
                ASSERT.isTrue(LANG.isDate(date), "Expected date.");
            },
            
            testParse: function() {
                var date = Y.DataType.Date.parse("December 17, 1995 03:24:00");
                ASSERT.isTrue(LANG.isDate(date), "Expected date.");

                date = Y.DataType.Date.parse(1995,11,17);
                ASSERT.isTrue(LANG.isDate(date), "Expected date.");

                date = Y.DataType.Date.parse(1995,11,17,3,24,0);
                ASSERT.isTrue(LANG.isDate(date), "Expected date.");

                date = Y.DataType.Date.parse(948548583);
                ASSERT.isTrue(LANG.isDate(date), "Expected date.");
            }
        });
        
        var testFormat = new Y.Test.Case({
            name: "Date Format Tests",

            testUndefined: function() {
                var output = Y.DataType.Date.format();
                ASSERT.areSame("", output, "Expected empty string.");
            },

            testNull: function() {
                var output = Y.DataType.Date.format(null);
                ASSERT.areSame("", output, "Expected empty string.");
            },
            
            testFormats: function() {
                var date = new Date(819199440000),
                    output;
                
                output = Y.DataType.Date.format(date);
                ASSERT.areSame("1995-12-17", output, "Expected default format (%F)");

                output = Y.DataType.Date.format(date, {format:"%D"});
                ASSERT.areSame("12/17/95", output, "Expected %D format.");

                output = Y.DataType.Date.format(date, {format:"%a %A"});
                ASSERT.areSame("Sun Sunday", output, "Expected %a %A format.");

                output = Y.DataType.Date.format(date, {format:"%b %B"});
                ASSERT.areSame("Dec December", output, "Expected %b %B format.");

                output = Y.DataType.Date.format(date, {format:"%r"});
                ASSERT.areSame("03:24:00 AM", output, "Expected %r format.");

                output = Y.DataType.Date.format(date, {format:"%R"});
                ASSERT.areSame("03:24", output, "Expected %R format.");
            }
        });
            
        var testFormatDeprecatedLocales = new Y.Test.Case({
            name: "Date Format Locale Tests",

            testUndefined: function() {
                Y.DataType.Date.Locale['fr'] = Y.merge(Y.DataType.Date.Locale, {
                	a: ['Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam'],
                	A: ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'],
                	b: ['Jan', 'Fév', 'Mar', 'Avr', 'Mai', 'Jun', 'Jui', 'Aoû', 'Sep', 'Cct', 'Nov', 'Déc'],
                	B: ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'],
                	c: '%a %d %b %Y %T %Z',
                	p: ['', ''],
                	P: ['', ''],
                	x: '%d.%m.%Y',
                	X: '%T'
                });

                Y.DataType.Date.Locale['fr-CH'] = Y.merge(Y.DataType.Date.Locale['fr'], { x: '%d. %m. %y' }, true);
                
                var date = new Date(819199440000),
                    output;

                output = Y.DataType.Date.format(date);
                ASSERT.areSame("1995-12-17", output, "Expected default format (%F).");

                output = Y.DataType.Date.format(date, {format:"%a %A", locale:"fr"});
                ASSERT.areSame("Dim Dimanche", output, "Expected %a %A format.");

                output = Y.DataType.Date.format(date, {format:"%b %B", locale:"fr"});
                ASSERT.areSame("Déc Décembre", output, "Expected %b %B format.");

                output = Y.DataType.Date.format(date, {format:"%x", locale:"fr"});
                ASSERT.areSame("17.12.1995", output, "Expected %x format.");

                output = Y.DataType.Date.format(date, {format:"%x", locale:"fr-CH"});
                ASSERT.areSame("17. 12. 95", output, "Expected %x format for fr-CH.");
            }
        });

        var testFormatUS = new Y.Test.Case({
            name: "Date Format U.S. Tests",

            testUS: function() {
                ASSERT.isNotNull(dateUS, "Expected U.S. Date to be loaded.");

                var date = new Date(819199440000),
                    output;

                output = dateUS.format(date);
                ASSERT.areSame("1995-12-17", output, "Expected default format (%F).");

                output = dateUS.format(date, {format:"%a %A"});
                ASSERT.areSame("Sun Sunday", output, "Expected %a %A format.");

                output = dateUS.format(date, {format:"%b %B"});
                ASSERT.areSame("Dec December", output, "Expected %b %B format.");

                output = dateUS.format(date, {format:"%x"});
                ASSERT.areSame("12/17/95", output, "Expected %x format.");

                output = dateUS.format(date, {format:"%r"});
                ASSERT.areSame("03:24:00 AM", output, "Expected %r format.");
            }
        });

        var testFormatFR = new Y.Test.Case({
            name: "Date Format French Tests",

            testFrench: function() {
                ASSERT.isNotNull(dateFR, "Expected French Date to be loaded.");

                var date = new Date(819199440000),
                    output;

                output = dateFR.format(date);
                ASSERT.areSame("1995-12-17", output, "Expected default format (%F).");

                output = dateFR.format(date, {format:"%a %A"});
                ASSERT.areSame("dim. dimanche", output, "Expected %a %A format.");

                output = dateFR.format(date, {format:"%b %B"});
                ASSERT.areSame("déc. décembre", output, "Expected %b %B format.");

                output = dateFR.format(date, {format:"%x"});
                ASSERT.areSame("17/12/95", output, "Expected %x format.");

                output = dateFR.format(date, {format:"%r"});
                ASSERT.areSame("03:24:00 AM", output, "Expected %r format.");
            }
        });

        var testFormatKR = new Y.Test.Case({
            name: "Date Format Korean Tests",

            testKorean: function() {
                ASSERT.isNotNull(dateKR, "Expected Korean Date to be loaded.");

                var date = new Date(819199440000),
                    output;

                output = dateKR.format(date);
                ASSERT.areSame("1995-12-17", output, "Expected default format (%F).");

                output = dateKR.format(date, {format:"%a %A"});
                ASSERT.areSame("일 일요일", output, "Expected %a %A format.");

                output = dateKR.format(date, {format:"%b %B"});
                ASSERT.areSame("12월 12월", output, "Expected %b %B format.");

                output = dateKR.format(date, {format:"%x"});
                ASSERT.areSame("95. 12. 17.", output, "Expected %x format.");

                output = dateKR.format(date, {format:"%r"});
                ASSERT.areSame("03:24:00 오전", output, "Expected %r format.");
            }
        });

        var testFormatIN = new Y.Test.Case({
            name: "Date Format Punjabi Tests",

            testPunjabi: function() {
                // provide data in Punjabi for India
                Y.Intl.add("datatype-date-format", "pa-IN", {
                        "a":["ਐਤ.","ਸੋਮ.","ਮੰਗਲ.","ਬੁਧ.","ਵੀਰ.","ਸ਼ੁਕਰ.","ਸ਼ਨੀ."],
                        "A":["ਐਤਵਾਰ","ਸੋਮਵਾਰ","ਮੰਗਲਵਾਰ","ਬੁਧਵਾਰ","ਵੀਰਵਾਰ","ਸ਼ੁੱਕਰਵਾਰ","ਸ਼ਨੀਚਰਵਾਰ"],
                        "b":["ਜਨਵਰੀ","ਫ਼ਰਵਰੀ","ਮਾਰਚ","ਅਪ੍ਰੈਲ","ਮਈ","ਜੂਨ","ਜੁਲਾਈ","ਅਗਸਤ","ਸਤੰਬਰ","ਅਕਤੂਬਰ","ਨਵੰਬਰ","ਦਸੰਬਰ"],
                        "B":["ਜਨਵਰੀ","ਫ਼ਰਵਰੀ","ਮਾਰਚ","ਅਪ੍ਰੈਲ","ਮਈ","ਜੂਨ","ਜੁਲਾਈ","ਅਗਸਤ","ਸਤੰਬਰ","ਅਕਤੂਬਰ","ਨਵੰਬਰ","ਦਸੰਬਰ"],
                        "c":"%a, %Y %b %d %l:%M:%S %p %Z",
                        "p":["ਸਵੇਰੇ","ਸ਼ਾਮ"],
                        "P":["ਸਵੇਰੇ","ਸ਼ਾਮ"],
                        "x":"%d/%m/%Y",
                        "X":"%l:%M:%S %p"
                    });
                // switch to Punjabi
                Y.Intl.setLang("datatype-date-format", "pa-IN");
                
                var dateIN = Y.DataType.Date;
                
                ASSERT.isNotNull(dateIN, "Expected Punjabi Date to be loaded.");

                var date = new Date(819199440000),
                    output;

                output = dateIN.format(date);
                ASSERT.areSame("1995-12-17", output, "Expected default format (%F).");

                output = dateIN.format(date, {format:"%a %A"});
                ASSERT.areSame("ਐਤ. ਐਤਵਾਰ", output, "Expected %a %A format.");

                output = dateIN.format(date, {format:"%b %B"});
                ASSERT.areSame("ਦਸੰਬਰ ਦਸੰਬਰ", output, "Expected %b %B format.");

                output = dateIN.format(date, {format:"%x"});
                ASSERT.areSame("17/12/1995", output, "Expected %x format.");

                output = dateIN.format(date, {format:"%r"});
                ASSERT.areSame("03:24:00 ਸਵੇਰੇ", output, "Expected %r format.");
            }
        });

        Y.Test.Runner.add(testParse);
        Y.Test.Runner.add(testFormat);
        Y.Test.Runner.add(testFormatDeprecatedLocales);
        Y.Test.Runner.add(testFormatUS);
        Y.Test.Runner.add(testFormatFR);
        Y.Test.Runner.add(testFormatKR);
        Y.Test.Runner.add(testFormatIN);
        Y.Test.Runner.run();
    });
})();
</script>
</body>
</html>
